package com.xyd.servlet;

import com.xyd.entity.Product;
import com.xyd.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/GetProductService")
public class GetProductService extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));
        ProductServiceImpl productService = new ProductServiceImpl();
        Product product=new Product();
        product.setEpName(name);
        Product product1= productService.getProduct(product);
        request.setAttribute("name",product1.getEpName());
        request.setAttribute("price",product1.getEpPrice());
        request.setAttribute("stock",product1.getEpStock());
        request.setAttribute("description",product1.getEpDescription());
        request.setAttribute("img",product1.getEpFileName());
        request.getRequestDispatcher("product-view.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
